<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数节流</title>
</head>
<body>
<label for="text">键盘按下函数节流</label><input type="text" id="text" />
<script>
    const text = document.getElementById('text')
    let timeId
    text.addEventListener('keyup', () => {
      if (timeId) {
        clearTimeout(timeId)
      }

      timeId = setTimeout(() => {
        console.log(text.value)
      }, 500)
    })

    /*const processor = {
      timeoutId: null,
      performProcess: function() {
        console.log(text.value)
      },
      process: function () {
        if (this.timeoutId) {
          clearTimeout(this.timeoutId)
        }
        this.timeoutId = setTimeout(() => {
          this.performProcess()
        }, 1000)
      }
    }
    processor.process()*/



</script>
</body>
</html>
